<%@page import="com.netistate.pojo.User"%>
<%@page import="com.netistate.pojo.TechNote"%>
<%@page import="com.netistate.pojo.Project"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>技术备忘录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/default.css" />
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/jquery.js"></script> 
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/common.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/table.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/msgbox/msgbox.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/techNote/techNote.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/calendar/Calendar.js"></script>
    <style type="text/css">
		.overTd {table-layout:fixed}
		.overTd td{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;padding:0px}
    </style>
  </head>
  <body>
    	<div class="toolbar" >
		    <a href="#" class='buttonlink txbtip' title='添加技术备忘录' onclick="addTechNote()"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/plus.png'/>添加技术备忘录</a>  
		    <a href="#" id="queryProjectButton" class='buttonlink txbtip' onclick="queryTechNote()" title='技术备忘录查询'><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/search.png'/>技术备忘录查询</a>
		    <a href="#" id="blurQueryProjectButton" class='buttonlink txbtip' onclick="blurQueryTechNote()" title='模糊查询'><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/search.png'/>模糊查询</a>  
		</div>
    	
    	<div id="blur_query_techNote" name="blur_query_techNote" class="toolbar" style="display:none;overflow:hidden;">
	     	<table>
	           <tr>
		    	<form id="queryTechNoteByProjectName" name="projectQuery_condition" action="" method="post" >
	                <td class="td_title" title="项目名称"><img alt="" src="${pageContext.request.contextPath}/images/common/save.gif">项目名称：</td>
	                <td class="td_title">
	                    <input id="blurByProjectName" type="text" name="blurByProjectName"/>
	                </td>
	                <td>
	                	<input onclick="bqtpn()" type="button" value="查询"/>
	                </td>
			     </form>
			     <form id="queryTechNoteByClientName" name="projectQuery_condition" action="" method="post" >
	                <td class="td_title" title="客户名称"><img alt="" src="${pageContext.request.contextPath}/images/common/save.gif">客户名称：</td>
	                <td class="td_title">
	                    <input id="blurByClientName" type="text" name="blurByClientName"/>
	                </td>
	                <td>
	                	<input onclick="bqtcn()" type="button" value="查询"/>
	                </td>
		     	</form>
	          </tr>
	        </table>
        </div>
    	<div id="query_techNote" name="query_techNote" class="" style="display:block;background-color:#D5E2F2;line-height:55px;font-size:12px">
		    <form id="queryTechNoteByCondition" name="projectQuery_condition" action="query_techNote_by_Condition.action" method="post" onSubmit="return queryTechNoteByConditionOnSubmit()" >
		        <table>
		           <tr>
		                <td class="td_title" title="项目名称"><img alt="" src="${pageContext.request.contextPath}/images/common/save.gif">项目名称：</td>
		                <td class="td_title">
		                    <select id="pid" name="pid" style="width:100px;">
								<!-- <option title="所有" value="所有">所有</option> -->
								<%	List<Project> projectList = (List<Project>)request.getSession().getAttribute("projectList");
									String queryPid = (String)request.getAttribute("queryPid");
									Project project = (Project)request.getAttribute("queryPidProject");
									
									if("所有".equals(queryPid) || queryPid == null){%>
									<option title="所有" selected value="所有">所有</option>
									<%	for(Project p : projectList){ %>
										<option title="<%=p.getProjectName()%>" value="<%=p.getId() %>"><%=p.getProjectName()%></option>
									<% 	}
									}else{%>
									<option title="所有" selected value="所有">所有</option>
									<%	for(Project p : projectList){ 
											if(p.getId() == Integer.parseInt(queryPid)){%>
											<option title="<%=project.getProjectName()%>" selected value="<%=project.getId() %>"><%=project.getProjectName()%></option>
										<%	} else { %>
											<option title="<%=p.getProjectName()%>" value="<%=p.getId() %>"><%=p.getProjectName()%></option>
									<% 		}	
										}
									} %>
		                    </select>
		                </td>
		                <%-- <td title="最新状态">最新状态：</td>
		                <td>
		                    <select id="state" name="state">
		                      <%String queryState = (String)request.getAttribute("queryState");
		                        if(queryState == null){%>
								   <option value="新增问题">新增问题</option>
								   <option value="未安排计划">未安排计划</option>
								   <option value="开发完成未上线">开发完成未上线</option>
								   <option value="开发完成已经上线">开发完成已经上线</option>
								   <option value="已经完成">已经完成</option>
								   <option value="取消跟踪">取消跟踪</option>
		                      <%}else{%>
		                      		<option value="<%=queryState %>"><%=queryState %></option>
		                      <%	if(!"所有".equals(queryState)){%>
		                      		<option value="所有">所有</option>
		                      <%	}
		                            if(!"新增问题".equals(queryState)){%>
		                            <option value="新增问题">新增问题</option>
		                      <%	}
		                            if(!"未安排计划".equals(queryState)){%>
	                                <option value="未安排计划">未安排计划</option><%
		                            }
		                            if(!"开发完成未上线".equals(queryState)){%>
	                                <option value="开发完成未上线">开发完成未上线</option><%
		                            }
		                            if(!"开发完成已经上线".equals(queryState)){%>
	                                <option value="开发完成已经上线">开发完成已经上线</option><%
		                            }
		                            if(!"已经完成".equals(queryState)){%>
	                                <option value="已经完成">已经完成</option><%
		                            }
		                            if(!"取消跟踪".equals(queryState)){%>
	                                <option value="取消跟踪">取消跟踪</option><%
		                            }
		                        }%>
		                    </select>
		                </td> --%>
		                	<td>
								<span id="lastStateDiv"  style="color:red" >最新状态&nbsp;&nbsp;</span>
								<div id="sortDiv" style="display:none;width:280px;height:45px;border-style:solid;border-width:1px;border-color: #4A95BA" >
									<input type="checkbox" checked name="state" value="新增问题"/>新增问题
									<input type="checkbox" checked name="state" value="未安排计划"/>未安排计划
									<input type="checkbox" checked name="state" value="开发完成未上线"/>开发完成未上线<br/>
									<input type="checkbox" name="state" value="开发完成已经上线"/>开发完成已经上线
									<input type="checkbox" name="state" value="已经完成"/>已经完成
									<input type="checkbox" name="state" value="取消跟踪"/>取消跟踪
								</div>
							</td>
							<script type="text/javascript">
								
								var jq=jQuery.noConflict();
								jq("#lastStateDiv").mousemove(function(){
									jq("#sortDiv").slideDown("slow").mouseleave(function(){
										jq(this).slideUp();
									});
								});
							</script>
		                
		                <td class="td_title" title="级别">级别：</td>
		                <td class="td_title">
		                    <select id="level" name="level" style="width:100px;">
		                    	<%String queryLevel = (String)request.getAttribute("queryLevel");
		                        if(queryLevel == null){%>
		                           	 <option title="所有" value="所有">所有</option>
									 <option title="紧急且重要" value="紧急且重要">紧急且重要</option>
									 <option title="紧急" value="紧急">紧急</option>
									 <option title="重要" value="重要">重要</option>
									 <option title="普通" value="普通">普通</option>
		                      <%}else{%>
		                      		<option value="<%=queryLevel %>"><%=queryLevel %></option>
		                      <%	if(!"所有".equals(queryLevel)){%>
		                      		<option value="所有">所有</option>
		                      <%	}
		                            if(!"紧急且重要".equals(queryLevel)){%>
		                            <option value="紧急且重要">紧急且重要</option>
		                      <%	}
		                            if(!"紧急".equals(queryLevel)){%>
	                                <option value="紧急">紧急</option>
	                          <%	}
		                            if(!"重要".equals(queryLevel)){%>
	                                <option value="重要">重要</option>
	                          <%	}
		                            if(!"普通".equals(queryLevel)){%>
	                                <option value="普通">普通</option>
	                          <%	}
		                        }%>
		                    </select>
		                </td>
		                 <td class="td_title" title="报告人">报告人：</td>
		                <td class="td_title">
		                    <select id="reporter" name="reporter" style="width:100px;">
								<%	List<User> userList = (List<User>)request.getSession().getAttribute("userList");
									String queryReporter = (String)request.getAttribute("queryReporter");
									User queryReporterUser = (User)request.getAttribute("queryReporterUser");
									if("所有".equals(queryReporter) || queryReporter == null){%>
									<option title="所有" selected value="所有">所有</option>
								<%		for(User u : userList){ %>
										<option value="<%=u.getUsername()%>"><%=u.getRealName()%></option>
								<%		}
									}else{ %>
									<option title="所有" selected value="所有">所有</option>
								<%		for(User u : userList){
											if(queryReporterUser.getUsername().equals(u.getUsername())){%>
											<option selected value="<%=queryReporterUser.getUsername()%>"><%=queryReporterUser.getRealName()%></option>
								<%			}else{%>
									<option value="<%=u.getUsername()%>"><%=u.getRealName()%></option>
								<%			}
										}
									}	%>
								<%-- <option title="所有" value="所有">所有</option>
								<c:forEach var="user" items="${sessionScope.userList }">
							   		<option value="${user.username }">${user.realName}</option>
							   	</c:forEach> --%>
		                    </select>
		                </td>
		                 <td class="td_title" title="处理人">处理人：</td>
		                <td class="td_title">
		                    <select id="doer" name="doer" style="width:100px;">
								<%	List<User> userLists = (List<User>)request.getSession().getAttribute("userList");
									String queryDoer = (String)request.getAttribute("queryDoer");
									User queryDoerUser = (User)request.getAttribute("queryDoerUser");
									if("所有".equals(queryDoer) || queryDoer == null){%>
									<option title="所有" selected value="所有">所有</option>
								<%		for(User u : userLists){ %>
										<option value="<%=u.getUsername()%>"><%=u.getRealName()%></option>
								<%		}
									}else{ %>
									<option title="所有" selected value="所有">所有</option>
								<%		for(User u : userLists){
											if(queryDoerUser.getUsername().equals(u.getUsername())){%>
											<option selected value="<%=queryDoerUser.getUsername()%>"><%=queryDoerUser.getRealName()%></option>
								<%			}else{%>
									<option value="<%=u.getUsername()%>"><%=u.getRealName()%></option>
								<%			}
										}
									}	%>
									<%-- <option title="所有" value="所有">所有</option>
								<c:forEach var="user" items="${sessionScope.userList }">
							   		<option value="${user.username }">${user.realName}</option>
							   	</c:forEach> --%>
		                    </select>
		                </td>
		                <td title="时间">时间：</td>
		                <td>
							<%
						        Date date = new Date();
							    SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
							    String endString = sdFormat.format(date);
							    Calendar calendar = Calendar.getInstance();
							    calendar.setTime(date);
							    calendar.add(Calendar.DATE,-7);
							    Date date2 = calendar.getTime();
							    String startString = sdFormat.format(date2);
							    String dayStart = (String)request.getAttribute("queryTechNoteBegintime");
							    String dayEnd = (String)request.getAttribute("queryTechNoteEndtime");
							    if(dayStart != null){
							         startString = dayStart;
							    }
							    if(dayEnd != null){
							         if(endString.equals(dayEnd)){
							             endString = "现在";
							         }else{
							              endString = dayEnd;
							         }
							    }else{
							        endString = "现在";
							    }
							 %>
							<input id="begintime" name="begintime" type="text" style="width:80px" onclick="MyCalendar.SetDate(this)" value="<%=startString %>" readonly="readonly" />
							</td>
							<td title="到">到</td>
							<td><input id="endtime" name="endtime" type="text" style="width:80px" onclick="MyCalendar.SetDate(this)" value="<%=endString %>" readonly="readonly" /></td>
		                	
		                	
		                	
			                <td><input type="submit" value="查询"   title="查询"/></td>
		           </tr>
		        </table>
		    </form>
		</div>
		
		<div id="show_techNote" style="width:100%;height:94%; overflow-y:scroll;overflow-x:hidden; border:1px solid;" >
			<table id="dArticleList" width="100%" border="0" cellpadding="0" cellspacing="1"  class="resizable overTd">
				<thead>
					<tr class="fixHead">
						<td  class="td1" style="cursor:pointer" width="7%">所属项目名称</td>
						<td  class="td1" style="cursor:pointer" width="5%">客户名称</td>
						<td  class="td1" style="cursor:pointer" width="5%">报告日期</td>
						<td  class="td1" style="cursor:pointer" width="6%">报告人</td>
						<td  class="td1" style="cursor:pointer" width="10%">简述</td>
						<td  class="td1" style="cursor:pointer" width="7%">类型</td>
						<td  class="td1" style="cursor:pointer" width="5%">处理人</td>
						<td  class="td1" style="cursor:pointer" width="6%">级别</td>
						<td  class="td1" style="cursor:pointer" width="8%">最新状态</td>
						<td  class="td1" style="cursor:pointer" width="10%">技术说明</td>
						<td  class="td1" style="cursor:pointer"  width="5%">预计完成时间</td>
						<td  class="td1"  width="5%">操作</td>
					</tr>
				</thead>
				<tbody>
					<%	List<TechNote> list = new ArrayList<TechNote>();
						List<TechNote> techNoteList = (List<TechNote>)request.getAttribute("tnList");
						if(techNoteList == null){
							list = (List<TechNote>)request.getSession().getAttribute("techNoteList");
						} else {
							list = techNoteList;
						}
						for(TechNote t : list){
						%>
						<tr onMouseOver= "this.bgColor   =   '#cccccc '; "   onMouseOut= "this.bgColor   =   '#FFFFFF'; " >  
				       		<td title="<%=t.getProject().getProjectName() %>" align="center" class="td2 txbtip" ><%=t.getProject().getProjectName() %>&nbsp;</td>
				       		<td title="<%=t.getProject().getClientName() %>" align="center" class="td2 txbtip" >
				       		<%if(t.getProject().getClientName() == null || "null".equals(t.getProject().getClientName())){ %>
			       			-&nbsp;
			       			<%}else{ %>
			       			<%=t.getProject().getClientName()%>&nbsp;
			       			<%} %>
				       		</td>
				       		<td title="<%=t.getReportDate() %>" align="center" class="td2 txbtip" ><%=t.getReportDate() %>&nbsp;</td>
				       		<td title="<%=t.getReporter() %>" align="center" class="td2 txbtip" ><%=t.getReporter() %>&nbsp;</td>
				       		<td title="<%=t.getDetailDesc() %>" style="text-overflow:ellipsis;overflow:hidden;" align="center" class="td2 txbtip" ><%=t.getBriefDesc() %>&nbsp;</td>
				       		<td title="<%=t.getType() %>" align="center" class="td2 txbtip" ><%=t.getType() %>&nbsp;</td>
				       		<td title="<%=t.getDoer() %>" align="center" class="td2 txbtip" ><%=t.getDoer() %>&nbsp;</td>
				       		<td title="<%=t.getLevel() %>" style="cursor: hand;" ondblclick="select_techNote_stl(<%=t.getId()%>)" align="center" class="td2 txbtip" ><%=t.getLevel() %>&nbsp;</td>
				       		<td title="<%=t.getState() %>" style="cursor: hand;" ondblclick="select_techNote_stl(<%=t.getId()%>)" align="center" class="td2 txbtip" ><%=t.getState() %>&nbsp;</td>
				       		<td title="<%=t.getTechDemon() %>" style="cursor: hand;text-overflow:ellipsis;overflow:hidden;" ondblclick="select_techNote_stl(<%=t.getId()%>)" align="left" class="td2 txbtip" ><%=t.getTechDemon() %>&nbsp;</td>
				       		<td title="<%=t.getClosetime() %>" align="center" ondblclick="select_techNote_stl(<%=t.getId()%>)" class="td2" ><%=t.getClosetime() %>&nbsp;</td>
				       		<td title="" align="center" class="td2" >
				       			<a href="#" class='buttonlink txbtip' title='修改' onclick="editTechNotes(<%=t.getId()%>)"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/edit.png'/></a>
				       			<img width='16' height='16' src='${pageContext.request.contextPath}/images/common/elbow-line.gif'/>
				       			<a href="#" class='buttonlink txbtip' title='删除' onclick="delTechNote('<%=t.getId()%>','你确定要删除？')" ><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/delete.png'/></a>
				       		</td>
						</tr>	
					  <%}%>	
				</tbody>
			</table>
		</div>
    	<script type="text/javascript">
    		
    		function queryTechNoteByConditionOnSubmit(){
				//query_techNote_by_Condition.action
				var states = document.getElementsByName("state");
				//var queryTechNoteByCondition = document.getElementById("queryTechNoteByCondition");
				
				var manyState = "";
				for(var i = 0;i < states.length;i++){
					if(states[i].checked){
						manyState+=states[i].value+',';
					};
				};
				
				var statesLength = manyState.split(",");
				if(statesLength.length < 2){
				 	PigossMsg.alert("最新状态至少选一个！");
				   	return false;
				};/* else{
					queryTechNoteByProjectName.action = "query_techNote_by_Condition.action";
    				queryTechNoteByProjectName.submit();
    			} */
    		};
    		
    	
    		//项目名模糊查询提交
    		function bqtpn(){
    			var blurByProjectName = document.getElementById("blurByProjectName").value;
    			var queryTechNoteByProjectName = document.getElementById("queryTechNoteByProjectName");
    			if(blurByProjectName == "" || blurByProjectName == null){
    				PigossMsg.alert("项目名称不能为空");
    				return;
    			}else{
    				queryTechNoteByProjectName.action = "blur_query_techNote_projectName.action";
    				queryTechNoteByProjectName.submit();
    			};
    		};
    	
    		//客户名模糊查询提交
    		function bqtcn(){
    			var blurByClientName = document.getElementById("blurByClientName").value;
    			var queryTechNoteByClientName = document.getElementById("queryTechNoteByClientName");
    			if(blurByClientName == "" || blurByClientName == null){
    				PigossMsg.alert("客户名称不能为空");
    				return;
    			}else{
    				queryTechNoteByClientName.action = "blur_query_techNote_clientName.action";
    				queryTechNoteByClientName.submit();
    			};
    		};
    	
    	
    		//刷新操作
    		function refreshTechNote(){
    			document.getElementById("queryTechNoteByCondition").submit();
    		};
    		
    	
    		//编辑技术备忘录
    		function editTechNotes(tid){
    			AjaxUtil.request({
					url : 'select_TechNote_stl.action',
					params : {id:tid},
					success : function(responseText){
    					PigossMsg.show("${pageContext.request.contextPath}/jsp/techNote/editTechNote.jsp","编辑技术备忘录",530,510,"editTechNote.update_techNote("+tid+")");
					},
					failure : function(){
						PigossMsg.alert("修改失败!");
					}
				});
    		};
    		
    		
    		//删除技术备忘录
    		function delTechNote(tid){
				PigossMsg.confirm("您确定要删除这条技术备忘录吗？",null,function yesHandler(){editTechNote.del(tid)},function noHandler(){});
    		};
    	
    		
    	
    		//编辑三个常用状态
    		function select_techNote_stl(id){
    			AjaxUtil.request({
					url : 'select_TechNote_stl.action',
					params : {id:id},
					success : function(responseText){
    					PigossMsg.show("${pageContext.request.contextPath}/jsp/techNote/editTechNoteState.jsp","编辑技术备忘录",320,360,"editTechNote.saveTechNoteState("+id+")");
					},
					failure : function(){
						PigossMsg.alert("修改失败!");
					}
				});
    			
    		};
    	
    		//添加技术备忘录，有发送邮件的功能
    		function addTechNote(){
    			var btnHTML = "<a href=\"javascript:AddTechNote.saveTechNote();\" class='buttonlink txbtip' title='保存'><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/save.gif'/><p>保存</p><a href=\"javascript:AddTechNote.saveTechNoteAndSendEmail();\" class='buttonlink txbtip' title='保存并发送邮件'><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/save.gif'/><p>保存并发送邮件</p></a><img src='${pageContext.request.contextPath}/images/common/shux.gif' class='split'/>";
    			PigossMsg.showWin("${pageContext.request.contextPath}/jsp/techNote/addTechNote.jsp","添加技术备忘录",480,420,btnHTML);
    		};
    		
    		//模糊查询
    		function blurQueryTechNote(){
    		
    			var div = document.getElementById("blur_query_techNote");
    			var idiv = document.getElementById("query_techNote");
    			if(div.style.display == 'none'){
    				div.style.display = 'block';
    				idiv.style.display = 'none';
    			}else{
    				div.style.display = 'none';
    			};
    		};
    		
    		//条件查询切换
    		function queryTechNote(){
    			var div = document.getElementById("query_techNote");
    			var idiv = document.getElementById("blur_query_techNote");
    			if(div.style.display=='none'){
		            div.style.display='block';
		            idiv.style.display='none'; 
		        }else{
		           	div.style.display='none'; 
		        };
    		};
    		
    		//编辑技术备忘录的技术说明
    		function edit_techNote_techDemon(id){
    			//未完成，最好做成留言形式的
    			//alert(id);
    			
    		};
    		//编辑技术备忘录的状态
    		function edit_techNote_state(id){
    			PigossMsg.show("${pageContext.request.contextPath}/jsp/techNote/editTechNoteState.jsp","编辑技术备忘录状态",200,100,"editTechNote.saveTechNoteState("+id+")");
    		};    			
    		initTableWidget('dArticleList',Array('S','S',"S",'S','S','S','S','S','S','S',false));
    	</script>
    
  </body>
</html>
